package com.mqb.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author mqb
 * @date 2021/4/8 9:47
 */
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Bean
    PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("spencer")
                .password("$2a$10$qF6JeBrhLsXmB18Mh4VarOsWTkAS4dWIapvXdWmzRcDXQWmMk/Ahy")
                .roles("admin")
                .and()
                .withUser("maqb")
                .password("$2a$10$miKjLcPXLeWNS8UJEzjJQO/ecFS2nBXHIWgXgInOHPYYea4bt1PKa")
                .roles("user");
    }
}
